package com.example.controller;

import com.example.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Administrator on 2017-4-24.
 */

@Controller
public class HelloController {
    @RequestMapping("/")
    public String index(ModelMap map){

        map.addAttribute("host", "http://www.baidu.com");
        // return模板文件的名称，对应src/main/resources/templates/index.html
        map.addAttribute("user", new User());
        return "index";
    }

    @PostMapping("/postUser")
    public String putUser(@ModelAttribute User user){

        System.out.println("user.userName = " + user.getUserName());
        System.out.printf("User = "+user.toString());

        return "success";
    }

}
